#include<bits/stdc++.h>
using namespace std;
#define l long long
l t, n, a[200005], ans;
unordered_map<l, l>mp;
void dfs(int dep, l score, l lastred, l lastblue) {
    if (dep > n) ans = max(ans, score);
    else {
        dfs(dep + 1, score + lastred, a[dep], lastblue);
        dfs(dep + 1, score + lastblue, lastred, a[dep]);
    }
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    while (t--) {
        cin >> n;
        ans = 0;
        for (int i = 1; i <= n; i++) cin >> a[i], mp[a[i]]++;
        if (pow(2, n) <= 1e8) dfs(1, 0, 0, 0);
        else {
            for (auto i : mp) ans += i.first * (i.second - 1);
        }
        cout << ans << "\n";
    }
}
